import 'package:flutter/material.dart';
import 'package:vmall_app/models/goods.dart';
import 'package:vmall_app/widgets/goods_list.dart';
import 'package:vmall_app/widgets/home_banner.dart';
import 'package:vmall_app/widgets/home_category.dart';
import 'package:vmall_app/widgets/home_swipper.dart';

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  var selectedIndex = 0;
  var bannerHeight = 30.0;
  ScrollController controller;
  String _selectedCategory;
  @override
  void initState() {
    controller = ScrollController();
    super.initState();
  }

  @override
  void dispose() {
    controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    var goods = getGoods();
    return SafeArea(
        child: Scaffold(
            backgroundColor: Color(0xFF7775),
            body: Stack(children: [
              Container(
                height: 120,
                color:Colors.white,
              ),
              Column(
                children: <Widget>[
                  HomeBanner(),
                  Expanded(
                      child: Container(
                    color: Colors.grey,
                    child: CustomScrollView(
                      physics: BouncingScrollPhysics(),
                      slivers: <Widget>[
                        SliverToBoxAdapter(
                          child: Row(
                            children: <Widget>[
                              Container(
                                padding: const EdgeInsets.all( 5),
                                width: MediaQuery.of(context).size.width - 35,
                                height: 30,
                                child: HomeCategory(
                                  onCategoryClick: (name) {
                                    setState(() {
                                      _selectedCategory = name;
                                    });
                                  },
                                ),
                              ),
                              Icon(
                                Icons.list,
                                color: Colors.black,
                              )
                            ],
                          ),
                        ),
                        SliverToBoxAdapter(
                          child: HomeSwipper(),
                        ),
                        SliverGrid(
                            gridDelegate:
                                SliverGridDelegateWithFixedCrossAxisCount(
                                    crossAxisCount: 2,
                                    crossAxisSpacing: 0,
                                    childAspectRatio: 0.68),
                            delegate: SliverChildBuilderDelegate(
                                (context, index) => Container(
                                      color: Colors.white,
                                      child: GoodsCard(
                                        buyCount: goods[index].buyCount,
                                        name: goods[index].name,
                                        price: goods[index].price,
                                        discountPrice:
                                            goods[index].discountPrice,
                                        imageUrl: goods[index].imagegUrl,
                                        goodsId: goods[index].id,
                                      ),
                                    ),
                                childCount: goods.length))
                      ],
                    ),
                  ))
                ],
              ),
            ])));
  }
}
